import {CHANGE_NOTIFY_COUNT, USER_SAVE, SAVE_CURRENT_USER} from "./const";

const initState = {
  list: [],
  currentUser: {},
};


export default function reducer(state = initState, {type, payload}) {
  switch (type) {
    case USER_SAVE:
      return {
        ...state,
        list: payload,
      };
    case SAVE_CURRENT_USER:
      return {
        ...state,
        currentUser: payload || {},
      };
    case CHANGE_NOTIFY_COUNT:
      return {
        ...state,
        currentUser: {
          ...state.currentUser,
          notifyCount: payload.totalCount,
          unreadCount: payload.unreadCount,
        },
      };
    default:
      return state;
  }
}
